package com.ds.map_set.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: TODO
 * @date 2022/10/16 18:27
 */
public class Num387_FirstUniqChar {
    public int firstUniqChar(String s) {
        char[] ret = s.toCharArray();
        Map<Character,Integer> map = new HashMap<>();
        for(char i : ret){
            if(map.containsKey(i)){
                map.put(i,map.get(i)+1);
            }else{
                map.put(i,1);
            }
        }
        for(int i= 0;i<ret.length;i++){
            if(map.get(ret[i])==1){
                return i;
            }
        }
        return -1;
    }
}
